// pages/hospital_detail/index.js
const app     = getApp()
const request = require('../../utils/request.js');
const config = require('../../utils/config.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
       detail:null,
       id:0  ,
       card_id:0,
       lng: '',
       lat: '',
       longitude:'',
       latitude:''
    },
    getCitys(){
        var that =this;
        if(that.data.lng==''){
            app.getLocation(function (res) {
                // 经度
                console.log(res)
                var lng = res.longitude
                // 纬度
                var lat = res.latitude
                that.setData({
                  lng: lng,
                  lat: lat,
                  longitude:lng,
                  latitude:lat
                })
                that.getDetail(); 
            
              });
        }else{
            this.getDetail(); 
        }
       
     
    },
    openmap(e){
        var that =this
       var mdata = that.data.detail;
        if(mdata){
            var address=mdata.province+mdata.city+mdata.area+mdata.address;
      
            wx.openLocation({
      
              latitude:Number(mdata.lat),
              
              longitude: Number(mdata.lng),
              
              name: mdata.hospital_name,
              
              address: address,
              
              scale: 18,
              
              success: function(res) {
              
              console.log(res)
              
              },
              
              fail: function(err) {
              
              console.log(err)
              
              }
              
              })
              
              
       
        }
        },
        appiont(){
            var json={},that =this;
            json.card_id=that.data.card_id;
            request.requestLoading(
             "/api/mine/checkInfo",
             json,
             'POST',
           ).then((res) => {
            
            if(res.code==1){
                wx.navigateTo({
                    url: '/pages/make_appointment/index?card_id='+that.data.card_id+'&hosptial_id='+that.data.id+'&tags_id='+that.data.tags_id,
                  })
          
            }
            
            
       
           }).catch((err) => {
             console.error(err);
           });
          
        },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            id:options.hosptial_id,
            card_id:options.card_id,
            tags_id:options.tags_id
        }) 
        this.getCitys()
       
    },
    getDetail(){
        var that = this;
        var json = {};
        json.id = this.data.id;
        json.lat=this.data.lat;
        json.lng=this.data.lng;
    
       
        request.requestLoading(
            "/api/Appoint/hospitalDetail",
            json,
            'POST',
          ).then((res) => {
           that.setData({
            detail:res.data
           })
          
           
           
      
          }).catch((err) => {
            console.error(err);
          });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        this.getDetail()
        setTimeout(function(){
          wx.stopPullDownRefresh();
        },500)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

   
})